﻿@using Abp.Application.Services.Dto
@using Abp.Extensions
@using Abp.Web.Mvc.Extensions
@using Abp.Timing;
@using MyCompanyName.AbpZeroTemplate.Web.Navigation
@model MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Settings.SettingsViewModel
@{
    ViewBag.CurrentPageName = PageNames.App.Tenant.Settings;
}
@section Scripts
{
    @Html.IncludeScript("~/Areas/Mpa/Views/Settings/Index.js")
}
<div class="row margin-bottom-5">
    <div class="col-xs-6">
        <div class="page-head">
            <div class="page-title">
                <h1>
                    <span>@L("Settings")</span> <small>@L("SettingsHeaderInfo")</small>
                </h1>
            </div>
        </div>
    </div>
    <div class="col-xs-6 text-right">
        <button id="SaveAllSettingsButton" class="btn btn-primary blue"><i class="fa fa-floppy-o"></i> @L("SaveAll")</button>
    </div>
</div>
<div class="portlet light margin-bottom-0">
    <div class="portlet-body">

        <div id="SettingsTabPanel" class="tabbable-line">
            <ul class="nav nav-tabs ">
                @if (Clock.SupportsMultipleTimezone)
                {
                    <li class="active">
                        <a href="#SettingsGeneralTab" data-toggle="tab" aria-expanded="true">
                            @L("General")
                        </a>
                    </li>
                }
                
                <li class="@(!Clock.SupportsMultipleTimezone ? "active" : "")">
                    <a href="#SettingsAppearanceTab" data-toggle="tab" aria-expanded="false">
                        @L("Appearance")
                    </a>
                </li>

                <li>
                    <a href="#SettingsUserManagementTab" data-toggle="tab" aria-expanded="false">
                        @L("UserManagement")
                    </a>
                </li>

                <li>
                    <a href="#SecurityManagementTab" data-toggle="tab" aria-expanded="false">
                        @L("Security")
                    </a>
                </li>

                @if (!ViewBag.IsMultiTenancyEnabled)
                {
                    <li class="">
                        <a href="#SettingsEmailSmtpTab" data-toggle="tab" aria-expanded="false">
                            @L("EmailSmtp")
                        </a>
                    </li>
                }
            </ul>

            <div class="tab-content">

                @if (Clock.SupportsMultipleTimezone)
                {
                    <div class="tab-pane active" id="SettingsGeneralTab">
                        <form id="GeneralSettingsForm">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                @Html.DropDownList("Timezone", Model.TimezoneItems.Select(i => i.ToSelectListItem()), new { @class = "form-control edited" })
                                <label>@L("Timezone")</label>
                            </div>
                            <div>
                                @Html.Hidden("TimezoneForComparison", Model.Settings.General.TimezoneForComparison)
                            </div>
                        </form>
                    </div>
                }
                
                <div class="tab-pane @((!Clock.SupportsMultipleTimezone) ? "active" : "")" id="SettingsAppearanceTab">
                    <div class="row">
                        <div class="col-sm-6">
                            <form id="SettingsLogoUploadForm" method="POST" action="@Url.Action("UploadLogo", "TenantCustomization", new {area = string.Empty})">
                                <div class="form-group">
                                    <input type="file" name="ApplicationLogoImage" />
                                    <span class="help-block m-b-none">@L("UploadLogo_Info")</span>
                                </div>
                                <button class="btn btn-primary" type="submit">@L("Upload")</button>
                                <button class="btn btn-default" type="reset">@L("Clear")</button>
                            </form>
                        </div>
                        <div class="col-sm-6">
                            <form id="SettingsCustomCssUploadForm" method="POST" action="@Url.Action("UploadCustomCss", "TenantCustomization", new {area = string.Empty})">
                                <div class="form-group">
                                    <input type="file" name="CustomCssFile" />
                                    <span class="help-block m-b-none">@L("UploadCSS_Info")</span>
                                </div>
                                <button class="btn btn-primary" type="submit">@L("Upload")</button>
                                <button class="btn btn-default" type="reset">@L("Clear")</button>
                            </form>
                        </div>
                    </div>
                </div>

                <div class="tab-pane" id="SettingsUserManagementTab">

                    <form id="FormBasedRegistrationSettingsForm">
                        <h4>@L("FormBasedRegistration")</h4>
                        <div class="md-checkbox-list">
                            <div class="md-checkbox">
                                <input id="Setting_AllowSelfRegistration" class="md-check" type="checkbox" name="AllowSelfRegistration" value="true" @(Model.Settings.UserManagement.AllowSelfRegistration ? "checked=\"checked\"" : "")>
                                <label for="Setting_AllowSelfRegistration">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("AllowUsersToRegisterThemselves")
                                </label>
                                <span class="help-block">@L("AllowUsersToRegisterThemselves_Hint")</span>
                            </div>
                            <div class="md-checkbox">
                                <input id="Setting_IsNewRegisteredUserActiveByDefault" class="md-check" type="checkbox" name="IsNewRegisteredUserActiveByDefault" value="true" @(Model.Settings.UserManagement.IsNewRegisteredUserActiveByDefault ? "checked=\"checked\"" : "")>
                                <label for="Setting_IsNewRegisteredUserActiveByDefault">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("NewRegisteredUsersIsActiveByDefault")
                                </label>
                                <span class="help-block">@L("NewRegisteredUsersIsActiveByDefault_Hint")</span>
                            </div>
                            <div class="md-checkbox">
                                <input id="Setting_UseCaptchaOnRegistration" class="md-check" type="checkbox" name="UseCaptchaOnRegistration" value="true" @(Model.Settings.UserManagement.UseCaptchaOnRegistration ? "checked=\"checked\"" : "")>
                                <label for="Setting_UseCaptchaOnRegistration">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("UseCaptchaOnRegistration")
                                </label>
                            </div>
                        </div>
                    </form>

                    @if (!ViewBag.IsMultiTenancyEnabled && Model.Settings.Ldap.IsModuleEnabled)
                    {
                        <form id="LdapSettingsForm">
                            <h4>@L("LdapSettings")</h4>
                            <div class="md-checkbox-list">
                                <div class="md-checkbox">
                                    <input id="Setting_LdapIsEnabled" class="md-check" type="checkbox" name="IsEnabled" value="true" @(Model.Settings.Ldap.IsEnabled ? "checked=\"checked\"" : "")>
                                    <label for="Setting_LdapIsEnabled">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("EnableLdapAuthentication")
                                    </label>
                                </div>
                            </div>
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="Domain" class="form-control@(Model.Settings.Ldap.Domain.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Ldap.Domain" maxlength="128">
                                <label>@L("DomainName")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="UserName" class="form-control@(Model.Settings.Ldap.UserName.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Ldap.UserName" maxlength="128">
                                <label>@L("UserName")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="password" name="Password" class="form-control@(Model.Settings.Ldap.Password.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Ldap.Password" maxlength="128">
                                <label>@L("Password")</label>
                            </div>
                        </form>
                    }

                    <form id="OtherSettingsForm">
                        <h4>@L("OtherSettings")</h4>
                        <div class="md-checkbox-list">
                            <div class="md-checkbox">
                                <input id="Settings_IsEmailConfirmationRequiredForLogin" class="md-check" type="checkbox" name="IsEmailConfirmationRequiredForLogin" value="true" @(Model.Settings.UserManagement.IsEmailConfirmationRequiredForLogin ? "checked=\"checked\"" : "")>
                                <label for="Settings_IsEmailConfirmationRequiredForLogin">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("EmailConfirmationRequiredForLogin")
                                </label>
                            </div>
                        </div>
                    </form>
                </div>

                <div id="SecurityManagementTab" class="tab-pane">
                    <div>
                        <h4>@L("PasswordComplexity")</h4>
                        <div class="md-checkbox-list">
                            <div class="md-checkbox">
                                <input id="Setting_PasswordComplexity_UseDefaultSettings" class="md-check" type="checkbox" name="UseDefaultSettings" value="true" @(Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "checked=\"checked\"" : "")>
                                <label for="Setting_PasswordComplexity_UseDefaultSettings">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("UseDefaultSettings")
                                </label>
                            </div>
                        </div>
                        <form id="PasswordComplexitySettingsForm" style="@(Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "display:none;" : "")">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="MinLength" class="form-control edited" value="@Model.Settings.Security.PasswordComplexity.MinLength">
                                <label>@L("MinPasswordLength")</label>
                            </div>
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="MaxLength" class="form-control edited" value="@Model.Settings.Security.PasswordComplexity.MaxLength">
                                <label>@L("MaxPasswordLength")</label>
                            </div>
                            <div class="md-checkbox-list">
                                <div class="md-checkbox">
                                    <input id="Setting_PasswordComplexity_UseNumbers" class="md-check" type="checkbox" name="UseNumbers" value="true" @(Model.Settings.Security.PasswordComplexity.UseNumbers ? "checked=\"checked\"" : "")>
                                    <label for="Setting_PasswordComplexity_UseNumbers">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseNumbers")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_PasswordComplexity_UseUpperCaseLetters" class="md-check" type="checkbox" name="UseUpperCaseLetters" value="true" @(Model.Settings.Security.PasswordComplexity.UseUpperCaseLetters ? "checked=\"checked\"" : "")>
                                    <label for="Setting_PasswordComplexity_UseUpperCaseLetters">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseUpperCaseLetters")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_PasswordComplexity_UseLowerCaseLetters" class="md-check" type="checkbox" name="UseLowerCaseLetters" value="true" @(Model.Settings.Security.PasswordComplexity.UseLowerCaseLetters ? "checked=\"checked\"" : "")>
                                    <label for="Setting_PasswordComplexity_UseLowerCaseLetters">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseLowerCaseLetters")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_PasswordComplexity_UsePunctuations" class="md-check" type="checkbox" name="UsePunctuations" value="true" @(Model.Settings.Security.PasswordComplexity.UsePunctuations ? "checked=\"checked\"" : "")>
                                    <label for="Setting_PasswordComplexity_UsePunctuations">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UsePunctuations")
                                    </label>
                                </div>
                            </div>
                        </form>
                        <form id="DefaultPasswordComplexitySettingsForm" style="@(!Model.Settings.Security.UseDefaultPasswordComplexitySettings ? "display:none;" : "")">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="MinLength" class="form-control edited" value="@Model.Settings.Security.DefaultPasswordComplexity.MinLength" disabled>
                                <label>@L("MinPasswordLength")</label>
                            </div>
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="MaxLength" class="form-control edited" value="@Model.Settings.Security.DefaultPasswordComplexity.MaxLength" disabled>
                                <label>@L("MaxPasswordLength")</label>
                            </div>
                            <div class="md-checkbox-list">
                                <div class="md-checkbox">
                                    <input id="Setting_DefaultPasswordComplexity_UseNumbers" class="md-check" type="checkbox" name="UseNumbers" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.UseNumbers ? "checked=\"checked\"" : "") disabled>
                                    <label for="Setting_DefaultPasswordComplexity_UseNumbers">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseNumbers")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_DefaultPasswordComplexity_UseUpperCaseLetters" class="md-check" type="checkbox" name="UseUpperCaseLetters" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.UseUpperCaseLetters ? "checked=\"checked\"" : "") disabled>
                                    <label for="Setting_DefaultPasswordComplexity_UseUpperCaseLetters">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseUpperCaseLetters")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_DefaultPasswordComplexity_UseLowerCaseLetters" class="md-check" type="checkbox" name="UseLowerCaseLetters" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.UseLowerCaseLetters ? "checked=\"checked\"" : "") disabled>
                                    <label for="Setting_DefaultPasswordComplexity_UseLowerCaseLetters">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseLowerCaseLetters")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Setting_DefaultPasswordComplexity_UsePunctuations" class="md-check" type="checkbox" name="UsePunctuations" value="true" @(Model.Settings.Security.DefaultPasswordComplexity.UsePunctuations ? "checked=\"checked\"" : "") disabled>
                                    <label for="Setting_DefaultPasswordComplexity_UsePunctuations">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UsePunctuations")
                                    </label>
                                </div>
                            </div>
                        </form>
                    </div>
                    
                    <div>
                        <h4>@L("UserLockOut")</h4>
                        <form id="UserLockOutSettingsForm">
                            <div class="md-checkbox-list">
                                <div class="md-checkbox">
                                    <input id="Setting_UserLockOut_IsEnabled" class="md-check" type="checkbox" name="IsEnabled" value="true" @(Model.Settings.Security.UserLockOut.IsEnabled ? "checked=\"checked\"" : "")>
                                    <label for="Setting_UserLockOut_IsEnabled">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("EnableUserAccountLockingOnFailedLoginAttemts")
                                    </label>
                                </div>
                            </div>
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="MaxFailedAccessAttemptsBeforeLockout" class="form-control edited" value="@Model.Settings.Security.UserLockOut.MaxFailedAccessAttemptsBeforeLockout">
                                <label>@L("MaxFailedAccessAttemptsBeforeLockout")</label>
                            </div>
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="DefaultAccountLockoutSeconds" class="form-control edited" value="@Model.Settings.Security.UserLockOut.DefaultAccountLockoutSeconds">
                                <label>@L("DefaultAccountLockoutDurationAsSeconds")</label>
                            </div>
                        </form>
                    </div>
                    
                    @if (!ViewBag.IsMultiTenancyEnabled || Model.Settings.Security.TwoFactorLogin.IsEnabledForApplication)
                    {
                        <div>
                            <h4>@L("TwoFactorLogin")</h4>
                            <form id="TwoFactorLoginSettingsForm">
                                <div class="md-checkbox-list">
                                    <div class="md-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsEnabled" class="md-check" type="checkbox" name="IsEnabled" value="true" @(Model.Settings.Security.TwoFactorLogin.IsEnabled ? "checked=\"checked\"" : "")>
                                        <label for="Setting_TwoFactorLogin_IsEnabled">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            @L("EnableTwoFactorLogin")
                                        </label>
                                    </div>
                                    @if (!ViewBag.IsMultiTenancyEnabled)
                                    {
                                        <div class="md-checkbox">
                                            <input id="Setting_TwoFactorLogin_IsEmailProviderEnabled" class="md-check" type="checkbox" value="true" name="IsEmailProviderEnabled" @(Model.Settings.Security.TwoFactorLogin.IsEmailProviderEnabled ? "checked=\"checked\"" : "")>
                                            <label for="Setting_TwoFactorLogin_IsEmailProviderEnabled">
                                                <span class="inc"></span>
                                                <span class="check"></span>
                                                <span class="box"></span>
                                                @L("IsEmailVerificationEnabled")
                                            </label>
                                        </div>
                                        <div class="md-checkbox">
                                            <input id="Setting_TwoFactorLogin_IsSmsProviderEnabled" class="md-check" type="checkbox" value="true" name="IsSmsProviderEnabled" @(Model.Settings.Security.TwoFactorLogin.IsSmsProviderEnabled ? "checked=\"checked\"" : "")>
                                            <label for="Setting_TwoFactorLogin_IsSmsProviderEnabled">
                                                <span class="inc"></span>
                                                <span class="check"></span>
                                                <span class="box"></span>
                                                @L("IsSmsVerificationEnabled")
                                            </label>
                                        </div>
                                    }
                                    <div class="md-checkbox">
                                        <input id="Setting_TwoFactorLogin_IsRememberBrowserEnabled" class="md-check" type="checkbox" value="true" name="IsRememberBrowserEnabled" @(Model.Settings.Security.TwoFactorLogin.IsRememberBrowserEnabled ? "checked=\"checked\"" : "")>
                                        <label for="Setting_TwoFactorLogin_IsRememberBrowserEnabled">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            @L("AllowToRememberBrowserForTwoFactorLogin")
                                        </label>
                                    </div>
                                </div>
                            </form>
                        </div>
                    }
                </div>

                @if (!ViewBag.IsMultiTenancyEnabled)
                {
                    <div class="tab-pane" id="SettingsEmailSmtpTab">
                        <form id="EmailSmtpSettingsForm">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="email" name="DefaultFromAddress" class="form-control@(Model.Settings.Email.DefaultFromAddress.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.DefaultFromAddress" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxEmailAddressLength">
                                <label>@L("DefaultFromAddress")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="DefaultFromDisplayName" class="form-control@(Model.Settings.Email.DefaultFromDisplayName.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.DefaultFromDisplayName" maxlength="128">
                                <label>@L("DefaultFromDisplayName")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="SmtpHost" class="form-control@(Model.Settings.Email.SmtpHost.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpHost" maxlength="64">
                                <label>@L("SmtpHost")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="number" name="SmtpPort" class="form-control edited" value="@Model.Settings.Email.SmtpPort" maxlength="5">
                                <label>@L("SmtpPort")</label>
                            </div>

                            <div class="md-checkbox-list">
                                <div class="md-checkbox">
                                    <input id="Settings_SmtpEnableSsl" class="md-check" type="checkbox" name="SmtpEnableSsl" value="true" @Html.Raw(Model.Settings.Email.SmtpEnableSsl ? "checked=\"checked\"" : "")>
                                    <label for="Settings_SmtpEnableSsl">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseSsl")
                                    </label>
                                </div>
                                <div class="md-checkbox">
                                    <input id="Settings_SmtpUseDefaultCredentials" class="md-check" type="checkbox" name="SmtpUseDefaultCredentials" value="true" @Html.Raw(Model.Settings.Email.SmtpUseDefaultCredentials ? "checked=\"checked\"" : "")>
                                    <label for="Settings_SmtpUseDefaultCredentials">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        @L("UseDefaultCredentials")
                                    </label>
                                </div>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="SmtpDomain" class="form-control@(Model.Settings.Email.SmtpDomain.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpDomain" maxlength="128">
                                <label>@L("DomainName")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="SmtpUserName" class="form-control@(Model.Settings.Email.SmtpUserName.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpUserName" maxlength="128">
                                <label>@L("UserName")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="password" name="SmtpPassword" class="form-control@(Model.Settings.Email.SmtpPassword.IsNullOrEmpty() ? "" : " edited")" value="@Model.Settings.Email.SmtpPassword" maxlength="128">
                                <label>@L("Password")</label>
                            </div>
                        </form>
                    </div>
                }

            </div>



        </div>

    </div>
</div>
